//
//  IMTCarManager.m
//  NewCar
//
//  Created by 方人疋 on 2018/1/30.
//  Copyright © 2018年 skx926. All rights reserved.
// 车辆管理类

#import "IMTCarManager.h"
#import <objc/runtime.h>

static IMTCarManager *_sharedCarManager;

@interface IMTCarManager ()

@property (nonatomic, assign) double minuteTotalEnergy;
@property (nonatomic, assign) NSInteger minuteEnergyCount;
@property (nonatomic, assign) double previousUploadedMileage;

@end

@implementation IMTCarManager

+ (IMTCarManager *)sharedCarManager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedCarManager = [[IMTCarManager alloc] init];
    });
    return _sharedCarManager;
}

/// 添加统计
- (void)addCarStatisticsWithCarModel:(CarModel *)car {
    self.minuteTotalEnergy += car.energy;
    self.minuteEnergyCount += 1;
    
    if (self.minuteEnergyCount > 10 && self.previousUploadedMileage != car.mileage) {
        self.minuteEnergyCount = 0;
        self.minuteTotalEnergy = 0;
        self.previousUploadedMileage = car.mileage;
    }
}

@end
